﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Text;

namespace MvcStudy.Areas.Admin.Controllers
{
    public class HomeController : BaseController
    {
        //
        // GET: /Admin/Home/

        public ActionResult Index()
        {
            ViewBag.Page = "Admin/Home";
            return View();
        }

        public string Add()
        {
            return "Add";
        }

        public ActionResult BAIMINGDANG()
        {
            string ip = Request.UserHostAddress;
            if (IpWhiteDic.ContainsKey(ip))
            {
                return Content("您的IP已在白名单");
            }
            //示例，白名单IP到TXT文本文档，实际情况应从数据库中插入
            string path = string.Join("/", AppDomain.CurrentDomain.BaseDirectory, "App_Data", "IPWhite.txt");
            using (StreamWriter sw = new StreamWriter(path, true, Encoding.Default))
            {
                sw.WriteLine(ip);
                return Content("恭喜，您的IP已被列入白名单");
            }
            return Content("添加失败请刷新试试");
        }

        public ActionResult InvalidIp()
        {
            return Content("Sorry, your ip has been banned");
        }
    }
}
